//
//  XCSingleBottumView.m
//  SoundOfNature
//
//  Created by 梁新昌 on 16/3/14.
//  Copyright © 2016年 梁新昌. All rights reserved.
//

#import "XCSingleBottumView.h"
#import "OnlineAVplay.h"
#import "UIImageView+WebCache.h"
#import "XCPlayViewController.h"

@implementation XCSingleBottumView 

- (void)dealloc {
    
//    [[NSNotificationCenter defaultCenter] removeObserver:self];

    [_headImageView release];
    [_songNameLable release];
    [_singerNameLable release];
    [_touMingButton release];
    [_buttonPlay release];


    [super dealloc];
    
}
+ (instancetype)shareBottomViewBuild{
static XCSingleBottumView *bottomView = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        bottomView = [[XCSingleBottumView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 50, [UIScreen mainScreen].bounds.size.width, 50)];
        bottomView.backgroundColor = [UIColor colorWithWhite:0.902 alpha:0.3];
        
    });
    return bottomView;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.buttonPlay = [UIButton buttonWithType:UIButtonTypeSystem];
        _buttonPlay.frame = CGRectMake(self.bounds.size.width - 100, 10, 30, 30);
        [self.buttonPlay addTarget:self action:@selector(playerButtonAction) forControlEvents:UIControlEventTouchUpInside];
        
        self.buttonList = [UIButton buttonWithType:UIButtonTypeSystem];
        _buttonList.frame = CGRectMake(self.bounds.size.width - 50, 10, 30, 30);
        [_buttonList setImage:[[UIImage imageNamed:@"Image-bottumList"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [_buttonList addTarget:self action:@selector(buttonListAction) forControlEvents:UIControlEventTouchUpInside];
        //  头像
        self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 40, 40)];
        [_headImageView.layer setCornerRadius:20];
        _headImageView.layer.masksToBounds = YES;
        //    然后再给图层添加一个有色的边框
        _headImageView.layer.borderWidth = 1;
        _headImageView.layer.borderColor = [[UIColor cyanColor] CGColor];
        //  歌曲名字

        self.songNameLable = [[XCBaseLable alloc] initWithFrame:CGRectMake(_headImageView.bounds.size.width + 20, 4, self.bounds.size.width / 3, 21)];
        
        
        _songNameLable.font = [UIFont systemFontOfSize:14];
        //    歌手名称
        self.singerNameLable = [[XCBaseLable alloc] initWithFrame:CGRectMake(_headImageView.bounds.size.width + 20, 25, self.bounds.size.width / 4, 21)];
        
        _singerNameLable.font = [UIFont systemFontOfSize:10];
        _singerNameLable.textColor = [UIColor colorWithRed:0.702 green:0.702 blue:0.702 alpha:1.0];
          //  透明 button
        self.touMingButton = [UIButton buttonWithType:UIButtonTypeSystem];
        _touMingButton.frame = CGRectMake(0, 0, self.bounds.size.width / 2, 50);
        [_touMingButton addTarget:self action:@selector(pressAction) forControlEvents:(UIControlEventTouchUpInside)];

        
        
        [self addSubview:_touMingButton];
        [self addSubview:_singerNameLable];
        [self addSubview:_songNameLable];
        [self addSubview:_headImageView];
        [self addSubview:_buttonList];
        [self addSubview:_buttonPlay];
        
        
        [_singerNameLable release];
        [_songNameLable release];
        [_headImageView release];
        
//        消息通知
//        获取消息中心
//        NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
////        添加观察者
//        [center addObserver:self selector:@selector(receiveNotifition:) name:@"isNight" object:nil];
        
    }
    return self;
}

-(void)pressAction{
    
    [self.delegate sendpresentPlayView];
}
- (void)buttonListAction {
    [self.delegate sendButtonListAction];
}
- (void)playerButtonAction{
    
    if ([OnlineAVplay shareAVPlayer].isPlay) {
        [[OnlineAVplay shareAVPlayer] pause];
        [self.buttonPlay setBackgroundImage:[[UIImage imageNamed:@"Image-bottumPlay"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        
        [OnlineAVplay shareAVPlayer].isPlay = NO;
    } else {
        [[OnlineAVplay shareAVPlayer] play];
        [self.buttonPlay setBackgroundImage:[[UIImage imageNamed:@"Image-bottumStop"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [OnlineAVplay shareAVPlayer].isPlay = YES;
        
    }
    
}


@end
